package com.spark.lola.controller.logistics;

import com.spark.lola.logistics.constant.LogisticsConstant;
import com.spark.lola.logistics.entity.DriverInfo;
import com.spark.lola.logistics.mapper.DriverInfoMapper;
import com.spark.lola.logistics.service.DriverInfoService;
import com.spark.lola.logistics.service.IndexService;
import com.spark.lola.support.api.entity.EnterpriseTokenUser;
import com.spark.lola.support.common.util.ResponseBean;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;

/**
 * @author: Zhi-peng wang
 * @date: 2020/05/25 14:54
 **/
@RestController
@RequestMapping(value = "/api/logistics/driver", produces = "application/json;charset=utf-8")
@Api(value = "/api/logistics/driver", tags = "驾驶员信息接口")
public class DriverController {

    @Autowired
    private DriverInfoService driverInfoService;

    @Autowired
    private DriverInfoMapper driverInfoMapper;

    @Autowired
    private IndexService indexService;

    @ApiOperation(value = "获取驾驶员详情")
    @RequestMapping(value = "/findInfo", method = RequestMethod.POST)
    public ResponseBean findInfo(@SessionAttribute EnterpriseTokenUser<?> tokenUser) throws ParseException {
        DriverInfo driverInfo = new DriverInfo();
        if (tokenUser.getShiroUser().getId() != 528) {
            driverInfo = driverInfoMapper.findByEmpId(tokenUser.getShiroUser().getId());
        } else {
            driverInfo.setEmpId(tokenUser.getShiroUser().getId());
            driverInfo.setRealName(tokenUser.getShiroUser().getRealName());
        }
        driverInfo.setShiroUser(tokenUser.getShiroUser());
        return ResponseBean.success(driverInfo);
    }

    @ApiOperation(value = "获取报表数据")
    @RequestMapping(value = "/findAllData", method = RequestMethod.POST)
    public ResponseBean findAllData(@SessionAttribute EnterpriseTokenUser<?> tokenUser) throws ParseException {
        return ResponseBean.success(indexService.findAllData(LogisticsConstant.BiFindType.ALL, tokenUser.getShiroUser()));
    }

}
